<style lang="less">
  @import '../../styles/common.less';
</style>

<template>
  <div style="width: 760px; margin-top: 20px;">
    <Form ref="dataSet" :model="dataSet" :rules="ruleValidate" :label-width="110">
      <div class="ivu-row">
          <div style="float: left; width: 50%;">

            <FormItem label="网站标题：" prop="title">
              <Input v-model="dataSet.title" placeholder="请输入标题"></Input>
            </FormItem>
            <FormItem label="网站关键词：" prop="seo">
              <Input v-model="dataSet.seo" placeholder="请输入关键词"></Input>
            </FormItem>
          </div>
        <div style="float: left; width: 50%;">
          <FormItem label="联系方式：" prop="telephone">
            <Input v-model="dataSet.telephone" placeholder="联系方式"></Input>
          </FormItem>
          <FormItem label="底部信息：" prop="btom">
            <Input v-model="dataSet.btom" placeholder="请输入底部信息"></Input>
          </FormItem>
        </div>
      </div>
      <FormItem label="网站描述：" prop="desc">
        <Input v-model="dataSet.desc" type="textarea" :autosize="{minRows: 5,maxRows: 8}" placeholder="请输入描述"></Input>
      </FormItem>
      <FormItem label="自定义信息：" prop="odesc">
        <Input v-model="dataSet.odesc" type="textarea" :autosize="{minRows: 5,maxRows: 8}" placeholder="请输入其他自定义信息"></Input>
      </FormItem>

      <FormItem>
        <Button type="primary" @click="handleSubmit('dataSet')">提交</Button>
      </FormItem>
    </Form>
  </div>
</template>

<script>
    export default {
        name: "baseset",
        data(){
          return{
            dataSet:{
              title : '',
              seo : '',
              desc : '',
              btom : '',
              odesc : '',
              telephone : ''
            },
            ruleValidate:{
              title:[
                {required: true,message:'请输入标题',trigger:'blur'}
              ],
              seo:[
                {required: true,message:'请输入关键词',trigger:'blur'}
              ],
              desc:[
                {required: true,message:'请输入描述',trigger:'blur'}
              ],
              btom:[
                {required: true,message:'请输入底部信息',trigger:'blur'}
              ],
              odesc:[
                {required: true,message:'请输入自定义信息',trigger:'blur'}
              ],
              telephone:[
                {required: true,message:'请输入联系方式',trigger:'blur'}
              ]
            }
          }
        },
        methods:{
          handleSubmit(name) {
            this.$refs[name].validate((valid) => {
              if (valid) {
                let dataArr = new Array();
                dataArr.push({keyName:'title',keyValue:this.dataSet.title});
                dataArr.push({keyName:'seo',keyValue:this.dataSet.seo});
                dataArr.push({keyName:'desc',keyValue:this.dataSet.desc});
                dataArr.push({keyName:'btom',keyValue:this.dataSet.btom});
                dataArr.push({keyName:'odesc',keyValue:this.dataSet.odesc});
                dataArr.push({keyName:'telephone',keyValue:this.dataSet.telephone});

                this.$http.post('/school/updSet',dataArr).then(res =>{
                  this.$Message.success('更新成功!');
                });
              } else {
                this.$Message.error('更新失败!');
              }
            })
          }
        },
        mounted(){
          this.$http.get('/school/allSet').then(res => {
            let data = res.data.data;
            for(var d in data){
              var obj = data[d];

              switch (obj.keyName){
                case 'title':
                  this.dataSet.title = obj.keyValue;
                  break;
                case 'seo':
                  this.dataSet.seo = obj.keyValue;
                  break;
                case 'desc':
                  this.dataSet.desc = obj.keyValue;
                  break;
                case 'btom':
                  this.dataSet.btom = obj.keyValue;
                  break;
                case 'odesc':
                  this.dataSet.odesc = obj.keyValue;
                  break;
                case 'telephone':
                  this.dataSet.telephone = obj.keyValue;
                  break;
              }
            }
          });
        }
    }
</script>

<style scoped>

</style>
